<template>
    <div class="index-lists">
        <el-card class="!border-none" shadow="never">
            <el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true">
                <el-form-item label="客户名称" prop="customerName">
                    <el-input class="w-[280px]" v-model="queryParams.customerName" />
                </el-form-item>
                <el-form-item label="联系方式" prop="contactWay">
                    <el-select v-model="queryParams.contactWay" class="w-[280px]" clearable>
                        <el-option label="电话" value="1" />
                        <el-option label="微信" value="2" />
                        <el-option label="拜访" value="3" />
                    </el-select>
                </el-form-item>
                <el-form-item label="联系内容" prop="contactTypeId">
                    <el-input class="w-[280px]" v-model="queryParams.contactTypeId" />
                </el-form-item>
                <el-form-item label="联系类型" prop="contactType">
                    <el-select v-model="queryParams.contactType" class="w-[280px]" clearable>
                        <el-option label="全部" value="" />
                    </el-select>
                </el-form-item>
                <el-form-item label="创建人" prop="creatorName">
                    <el-input class="w-[280px]" v-model="queryParams.creatorName" />
                </el-form-item>
                <el-form-item label="下次跟进时间" prop="followUpTime">
                    <daterange-picker
                        v-model:startTime="queryParams.followUpTimeStart"
                        v-model:endTime="queryParams.followUpTimeEnd"
                    />
                </el-form-item>
                <el-form-item label="创建时间" prop="createTime">
                    <daterange-picker
                        v-model:startTime="queryParams.createTimeStart"
                        v-model:endTime="queryParams.createTimeEnd"
                    />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="!border-none mt-4" shadow="never">
            <div>
                <el-button type="primary">
                    <template #icon>
                        <icon name="el-icon-download" />
                    </template>
                    导出
                </el-button>
                <el-button type="primary">
                    <template #icon>
                        <icon name="el-icon-upload" />
                    </template>
                    导入
                </el-button>
            </div>
            <el-table class="mt-4" size="large" v-loading="pager.loading" :data="pager.lists" stripe>
                <el-table-column type="selection" width="55" />
                <el-table-column label="ID" prop="id" min-width="50" />
                <el-table-column label="客户名称" prop="customerName" min-width="180" />
                <el-table-column label="客户联系人" prop="customerContact" min-width="180" />
                <el-table-column label="联系内容" prop="contactContent" min-width="180" />
                <el-table-column label="联系时间" prop="contactTime" min-width="180" />
                <el-table-column label="我方联系人" prop="ourContactName" min-width="180" />
                <el-table-column label="联系方式" prop="contactWay" min-width="180" />
                <el-table-column label="联系类型" prop="contactType" min-width="180" />
                <el-table-column label="创建人" prop="creatorName" min-width="180" />
                <el-table-column label="下次跟进时间" prop="followUpTime" min-width="180" />
                <el-table-column label="创建时间" prop="createTime" min-width="180" />
                <el-table-column label="操作" width="120" fixed="right">
                    <template #default="{ row }">
                        <el-button
                            v-perms="['clientPhone:edit']"
                            type="primary"
                            link
                            @click="handleEdit(row)"
                        >
                            编辑
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
        <edit-popup
            v-if="showEdit"
            ref="editRef"
            :dict-data="dictData"
            @success="getLists"
            @close="showEdit = false"
        />
    </div>
</template>
<script lang="ts" setup name="clientPhone">
import { clientPhoneDelete, clientPhoneLists } from '@/api/clientPhone'
import { useDictData } from '@/hooks/useDictOptions'
import { usePaging } from '@/hooks/usePaging'
import feedback from '@/utils/feedback'
import EditPopup from './edit.vue'
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
const showEdit = ref(false)
const queryParams = reactive({
    customerName: '',
    contactContent: '',
    contactWay: '',
    contactTypeId: '',
    contactType: '',
    creatorName: '',
    followUpTimeStart: '',
    followUpTimeEnd: '',
    createTimeStart: '',
    createTimeEnd: ''
})

const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: clientPhoneLists,
    params: queryParams
})

// const handleAdd = async () => {
//   showEdit.value = true;
//   await nextTick();
//   editRef.value?.open("add");
// };

const handleEdit = async (data: any) => {
    showEdit.value = true
    await nextTick()
    editRef.value?.open('edit')
    editRef.value?.getDetail(data)
}

const handleDelete = async (id: number) => {
    await feedback.confirm('确定要删除？')
    await clientPhoneDelete({ id })
    feedback.msgSuccess('删除成功')
    getLists()
}

getLists()
</script>
